package com.yuanye.gwcit.fragments;

import com.yuanye.gwcit.GW;
import com.yuanye.yeecho.base.CommonTaskFragment;
import com.yuanye.yeecho.utils.YY;

public class SystemInfoFragment extends CommonTaskFragment {

    public SystemInfoFragment() {
        setTaskName("系统信息");
    }

    @Override
    public void execTask() {
        super.execTask();

        //中兴版本号
        String buildNumber = YY.execShell("getprop ro.build.version.incremental");
        String StdBuildNumber = GW.cfgPcba.getSysBuild();
        appendLog("中兴版本号："+buildNumber);
        appendLog("参考版本号："+StdBuildNumber);
        if (!buildNumber.equals(StdBuildNumber)){
            appendLogF("比对失败");
            setFail();
            return;
        }

        //kernel version
        String kernel = System.getProperty("os.version");
        String stdKernel = GW.cfgPcba.getSysKernel();
        appendLog("\n内核版本号："+kernel);
        appendLog("参考版本号："+stdKernel);
        if (!kernel.equals(stdKernel)){
            appendLogF("比对失败");
            setFail();
            return;
        }

        //hardware version
        String hardwareVersion = YY.execShell("getprop ro.boot.board.version");
        String stdHardwareVersion = GW.cfgPcba.getSysHwVer();
        appendLog("\n硬件版本号："+hardwareVersion);
        appendLog("参考版本号："+stdHardwareVersion);
        if (!hardwareVersion.equals(stdHardwareVersion)){
            appendLogF("比对失败");
            setFail();
            return;
        }

        //bom version
        String bomVersion = YY.execShell("getprop ro.boot.bom.version");
        String stdBomVersion = GW.cfgPcba.getSysBomVer();
        appendLog("\n物料版本号："+bomVersion);
        appendLog("参考版本号："+stdBomVersion);
        if (!bomVersion.equals(stdBomVersion)){
            appendLogF("比对失败");
            setFail();
            return;
        }

        //i2c检查
        String i2c = YY.execShell("ls /sys/devices/platform/fdd40000.i2c/of_node/");
        int count = i2c.split("\n").length;
        int stdCount = -1;
        try {
            stdCount = Integer.parseInt(GW.cfgPcba.getI2cCount());
        }catch (NumberFormatException e){
            appendLogF(e.toString());
            setFail();
            return;
        }
        if (i2c.isEmpty()){
            appendLogF("未找到I2C");
            setFail();
            return;
        }else{
            appendLog("\nI2C数量："+count);
            appendLog("参考数量："+stdCount);
            if (count != stdCount){
                appendLogF("比对失败");
                setFail();
                return;
            }
        }

        appendLog("\n信息校验成功");
        passAndNext();

    }
}
